package com.dlu.safe_construction.common.utils;

import org.springframework.web.multipart.MultipartFile;

import java.io.*;

/**
 * Created by 李家兴
 * Date 2020/1/31
 * Description
 */
public class FileUtils {

    public static File multipartFileToFile(MultipartFile multipartFile) throws IOException {
        InputStream ins = multipartFile.getInputStream();
        File file = new File(multipartFile.getOriginalFilename());
        OutputStream os = new FileOutputStream(file);
        int byteRead = 0;
        byte[] buffer = new byte[8192];
        while ((byteRead = ins.read(buffer, 0, 8192)) != -1) {
            os.write(buffer, 0, byteRead);
        }
        os.close();
        ins.close();
        return file;
    }
}
